<!--
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-03-22 12:12:49
 * @LastEditTime: 2022-07-27 15:04:06
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description:
 * @FilePath: \vue3-element-plus-web\src\App.vue
 * Copyright 版权声明
-->
<template>
  <el-config-provider :locale="locale">
    <router-view v-if="isReloadRouter"></router-view>
    <!-- 将上传组件全局注册 -->
    <global-uploader :global="true" />
  </el-config-provider>
</template>

<script>
import { mapGetters } from 'vuex'
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
import zhTw from 'element-plus/lib/locale/lang/zh-tw'
import en from 'element-plus/lib/locale/lang/en'
import GlobalUploader from '@/components/GlobalUploader'

export default {
  name: 'App',
  components: {
    GlobalUploader
  },
  computed: {
    ...mapGetters([
      'language'
    ]),
    locale: function() {
      let languageLocale = null
      switch (this.language) {
        case 'zh-cn':
          languageLocale = zhCn
          break
        case 'zh-tw':
          languageLocale = zhTw
          break
        case 'en':
          languageLocale = en
          break
        default:
          languageLocale = zhCn
      }
      return languageLocale
    }
  },
  data() {
    return {
      isReloadRouter: true
    }
  },
  provide() {
    return {
      reloadRouter: () => {
        this.reload()
      }
    }
  },
  methods: {
    reload() {
      console.log('------reload------')
      location.reload()
      // this.isReloadRouter = false
      // this.$nextTick(() => {
      //   this.isReloadRouter = true
      // })
    }
  }
}
</script>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
</style>
